package day01;



import org.junit.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class TestConnect {
    @Test
    public void test1() throws ClassNotFoundException, SQLException {
//加载驱动
        Class.forName("com.mysql.jdbc.Driver");
//
        String url="jdbc:mysql://127.0.0.1:3306/mysql_db?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai";
        String userName="root";
        String passWord="root";
//        获取数据库连接
        Connection connection = DriverManager.getConnection(url, userName, passWord);
        System.out.println("connection="+connection);

        String sql = "INSERT INTO emp(empno,ename) VALUES(800,'Jerry')";

        PreparedStatement ps = connection.prepareStatement(sql);

        int rows = ps.executeUpdate();

        System.out.println(rows>0?"添加成功":"添加失败");

        ps.close();
        connection.close();
    }
}